package com.aaa.service.fpa.impl;

import com.aaa.dao.fpa.ViewTestResultFpaDao;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.fpa.ResultDiv;
import com.aaa.entity.fpa.TestResultFpa;
import com.aaa.entity.fpa.ViewTestResultFpa;

import com.aaa.entity.mht.TestResultMht;
import com.aaa.service.fpa.ViewTestResultFpaService;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (ViewTestResultFpa)表服务实现类
 *
 * @author
 * @since 2022-09-05 11:42:04
 */
@Service("viewTestResultFpaService")
public class ViewTestResultFpaServiceImpl implements ViewTestResultFpaService {
    @Resource
    private ViewTestResultFpaDao viewTestResultFpaDao;

    /**
     * 分页查询
     *
     * @param viewTestResultFpa 筛选条件
     * @param pageSortEntity    分页对象
     * @return 查询结果
     */

    @Override
    public Page queryByPage(PageSortEntity pageSortEntity, ViewTestResultFpa viewTestResultFpa) {
        PageHelper.startPage(pageSortEntity.getPage(), pageSortEntity.getLimit(), pageSortEntity.getOrderString());
        List<ViewTestResultFpa> fpaList = viewTestResultFpaDao.queryAllByLimit(viewTestResultFpa);
        Page page = (Page) fpaList;
        return page;
    }

    @Override
    public Page queryTestResultById(PageSortEntity pageSortEntity, TestResultFpa testResultFpa) {
        PageHelper.startPage(pageSortEntity.getPage(), pageSortEntity.getLimit(), pageSortEntity.getOrderString());
        List<TestResultFpa> testResultFpas = viewTestResultFpaDao.queryTestResultById(testResultFpa);
        Page pageResult = (Page) testResultFpas;
        return pageResult;
    }


    /**
     * @param
     * @return Map
     * @create by: feng (zhaixing@163.com)
     * @description: 根据id查询对应信息
     * @create time:  2022-09-05 11:42:04
     */
    @Override
    public List<ViewTestResultFpa> queryRequestById(ViewTestResultFpa viewTestResultFpa) {

        List<ViewTestResultFpa> viewTestResultFpas = viewTestResultFpaDao.queryResultFpaById(viewTestResultFpa);
        return viewTestResultFpas;
    }


    /**
     * @param
     * @return Map<String   ,       Integer>
     * @create by: feng (zhaixing@163.com)
     * @description: 查询所有数据
     * @create time:  2022-09-05 11:42:04
     */
    @Override
    public Map<String, Integer> queryAllPlanFpa() {
        List<ViewTestResultFpa> viewTestResultFpas = this.viewTestResultFpaDao.queryAllPlanFpa();
        int r = 0, y = 0, b = 0, g = 0, f = 0;
        for (ViewTestResultFpa viewTestResultFpa : viewTestResultFpas) {
            double red = viewTestResultFpa.getRedCount();
            double yellow = viewTestResultFpa.getYellowCount();
            double blue = viewTestResultFpa.getBlueCount();
            double green = viewTestResultFpa.getGreenCount();
            if (red > yellow && red > blue && red > green) {
                r++;
            } else if (yellow > red && yellow > blue && yellow > green) {
                y++;
            } else if (blue > red && blue > yellow && blue > green) {
                b++;
            } else if (green > red && green > yellow && green > blue) {
                g++;
            } else {
                f++;
            }

        }
        Map<String, Integer> map = new HashMap<>();
        map.put("r", r);
        map.put("y", y);
        map.put("b", b);
        map.put("g", g);
        map.put("f", f);

        return map;


    }

    @Override
    public String selecById(Integer id) {
        ViewTestResultFpa viewTestResultFpa = viewTestResultFpaDao.seleResultFpa(id);
        double red = viewTestResultFpa.getRedCount();
        double yellow = viewTestResultFpa.getYellowCount();
        double blue = viewTestResultFpa.getBlueCount();
        double green = viewTestResultFpa.getGreenCount();
        if (red > yellow && red > blue && red > green) {
            return "fpaResult/red.jsp";
        } else if (yellow > red && yellow > blue && yellow > green) {
            return "fpaResult/yellow.jsp";
        } else if (blue > red && blue > yellow && blue > green) {
            return "fpaResult/blue.jsp";
        } else if (green > red && green > yellow && green > blue) {
            return "fpaResult/green.jsp";
        } else {
            return "fpaResult/All.jsp";
        }
    }


    /**
     * @return
     * @Descriptio
     * @Param
     **/
    @Override
    public ResultDiv queryAllResultDiv(Integer id) {
        return viewTestResultFpaDao.queryAllDiv(id);
    }

    /**
     * @param id
     * @return
     * @description: 删除
     */


    @Override
    public boolean deleteById(int[] id) {
        return viewTestResultFpaDao.deleteById(id);
    }

    @Override
    public boolean deleteByTesterId(int[] id) {
        return viewTestResultFpaDao.deleteByTesterId(id);
    }
}
